<template>
  <div id="billingreview">
    <div class="list-container">
      <div class="tables">
        <el-table
          :data="tableData"
          class="table"
          height="100%"
          ref="jdjgTable"
          @sort-change="sortChange"
          :header-cell-style="{
            padding: '0px',
            background: 'linear-gradient(0deg, #F4F6F9, #EAECF4, #F3F6F9)'
          }"
          :row-class-name="tabRowClassName"
          header-row-class-name="mapTable_th"
        >
          <el-table-column width="60" align="center" type="index" :index="addIndex" label="序号">
            <el-table-column width="60" align="center" type="index" label="检索"> </el-table-column>
          </el-table-column>
          <el-table-column label="申请企业" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="riseAddEnterprise">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="开票公司名称" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="rise">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="纳税人识别号" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="taxpayerCode">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="开票电话" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="drawerPhone">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="法人姓名" align="center" width="180">
            <el-table-column width="180" align="center" sortable="custom" prop="legalPerson">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="开户银行" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="bankOfDeposit">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="开户账号" align="center" width="150">
            <el-table-column width="150" align="center" sortable="custom" prop="accountNumber">
              <template slot="header" align="center" slot-scope="{}">
                <div class="searchBox" @click.stop>
                  <el-input v-model.trim="searchPositionName" @change="getDataChange"></el-input>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="状态" align="center" width="100">
            <el-table-column align="center" prop="auditStatus" width="100">
              <template slot-scope="scope">
                <div class="">
                  {{ scope.row.auditStatus === 0 ? '未审核' : scope.row.auditStatus === 1 ? '审核通过' : '审核驳回' }}
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="操作" align="center" fixed="right" width="80">
            <el-table-column align="center" width="80">
              <template slot-scope="scope">
                <div class="" v-if="scope.row.auditStatus == 0">
                  <el-button type="text" class="xg czBtn" size="small" @click="handleClick(scope.row)">
                    审核
                  </el-button>
                </div>
                <div class="" v-else>
                  <el-button type="text" class="xg czBtn" size="small" @click="handleClick(scope.row)">
                    查看
                  </el-button>
                </div>
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="pags">
      <element-pagination @getData="getPagChange" :Total="total"> </element-pagination>
    </div>

    <el-dialog
      class="billing_dialog"
      width="1200px"
      v-if="visiable"
      :center="true"
      :close-on-click-modal="false"
      title="开票抬头审核"
      :before-close="closeDialog"
      :visible.sync="visiable"
    >
      <div class="dialog-wrap">
        <div class="form-con">
          <div class="left">
            <el-form ref="form" class="infoForm" label-width="150px">
              <el-form-item label="发票抬头(公司名称)："> {{ billingFrom.rise }}</el-form-item>
              <el-form-item label="开票电话：">
                {{ billingFrom.drawerPhone }}
              </el-form-item>
              <el-form-item label="纳税人识别号:">
                {{ billingFrom.taxpayerCode }}
              </el-form-item>
              <el-form-item label="公司地址："> {{ billingFrom.province }}{{ billingFrom.address }} </el-form-item>
              <el-form-item label="开户银行："> {{ billingFrom.bankOfDeposit }}</el-form-item>
              <el-form-item label="开户账号："> {{ billingFrom.accountNumber }}</el-form-item>
              <el-form-item label="法人姓名："> {{ billingFrom.legalPerson }}</el-form-item>
              <el-form-item label="法人身份证号："> {{ billingFrom.legalPersonId }}</el-form-item>
              <el-form-item label="营业执照：">
                <el-image
                  style="width: 150px; height: 150px; cursor: pointer"
                  :src="billingFrom.businessLicense"
                  @click="imgCheck(billingFrom.businessLicense)"
                ></el-image>
              </el-form-item>
              <el-form-item label="法人证件照：">
                <el-image
                  style="width: 150px; height: 150px; cursor: pointer"
                  :src="billingFrom.idPhoto"
                  @click="imgCheck(billingFrom.idPhoto)"
                ></el-image>
              </el-form-item>
            </el-form>
          </div>
          <div class="right">
            <el-form ref="form" class="infoForm" style="margin-bottom: 20px">
              <el-form-item label="审核状态:">
                <span style="float: left">
                  {{ billingFrom.auditStatus | reviewStateFilter }}
                </span>

                <el-image
                  style="width: 60px; height: 45px; margin-left: 20px"
                  :src="require('../../../../assets/unreviewed.png')"
                  v-if="billingFrom.auditStatus === 0"
                >
                </el-image>
                <el-image
                  style="width: 60px; height: 45px; margin-left: 20px"
                  :src="require('../../../../assets/examination_passed.png')"
                  v-else-if="billingFrom.auditStatus === 1"
                >
                </el-image>
                <el-image
                  style="width: 60px; height: 45px; margin-left: 20px"
                  :src="require('../../../../assets/review_rejected.png')"
                  v-else
                >
                </el-image>
              </el-form-item>
            </el-form>
            <div v-if="billingFrom.auditStatus === 0">
              <div style="font-size: 14px; margin-bottom: 30px">
                <p>选择<span style="color: #ff0000">驳回</span>，需填写驳回理由，等待填报人修改后再次审核。</p>
                <p>选择<span style="color: #00a2ff">通过</span>，填报的工作内容将生效，不可撤销。</p>
              </div>
              <p style="margin-bottom: 30px">
                <el-radio v-model.trim="radio" label="1">通过</el-radio>
                <el-radio v-model.trim="radio" label="2">驳回</el-radio>
              </p>
              <div style="margin-bottom: 100px">
                <el-form ref="form" class="infoForm">
                  <el-form-item label="审核意见：">
                    <el-input
                      type="textarea"
                      :autosize="{ minRows: 3 }"
                      placeholder="请输入审核意见"
                      v-model.trim="auditopinion"
                    >
                    </el-input>
                  </el-form-item>
                </el-form>
              </div>
              <el-button size="small" @click="subMitBtn(billingFrom.id)"> 提交审核 </el-button>
            </div>
            <div v-else class="isreview">
              <el-form ref="form" class="infoForm" style="margin-bottom: 20px">
                <el-form-item label="审核人:">
                  {{ billingFrom.invoiceHeaderApprove.approveName }}
                </el-form-item>
                <el-form-item label="审核时间:">
                  {{ billingFrom.invoiceHeaderApprove.updateTime }}
                </el-form-item>
                <el-form-item label="审核结果:">
                  {{ billingFrom.invoiceHeaderApprove.auditStatus | reviewStateFilter }}
                </el-form-item>
                <el-form-item label="审核意见:">
                  {{ billingFrom.invoiceHeaderApprove.reason }}
                </el-form-item>
              </el-form>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>
    <el-image-viewer style="z-index: 99999" v-if="showViewer" :on-close="viewerClose" :url-list="stencilUrl" />
  </div>
</template>

<script>
import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
import ElementPagination from '../../../../components/ElementPagination.vue'
export default {
  data() {
    return {
      radio: null,
      auditopinion: '',
      visiable: false,
      billingFrom: {},
      searchPositionName: '',
      total: 0,
      page: 1,
      size: 15,
      tableData: [],
      stencilUrl: [],
      showViewer: false
    }
  },
  components: { ElementPagination, ElImageViewer },
  mounted() {
    this.getData()
  },
  filters: {
    reviewStateFilter(val) {
      if (val === null) {
        return
      }
      return val === 0 ? '未审核' : val === 1 ? '审核通过' : '审核驳回'
    }
  },
  methods: {
    subMitBtn(id) {
      if (this.radio) {
        if (this.radio === '2' && this.auditopinion == '') {
          this.$message.error('请填写驳回理由')
          return
        }

        this.$https({
          url: '/invoiceHeader/invoiceHeaderApprove',
          method: 'post',
          data: {
            invoiceHeaderId: id,
            reason: this.auditopinion,
            auditStatus: this.radio
          }
        }).then(res => {
          if (res.code === 0) {
            this.$message.success('审核成功')
            this.radio = null
            this.visiable = false
            this.billingFrom = {}
            this.getData()
          } else {
            this.$message.error(res.msg)
          }
        })
      } else {
        this.$message.error('请选择审核结果')
      }
    },
    viewerClose() {
      this.showViewer = false
      this.stencilUrl = []
    },
    // 查看图片大图
    imgCheck(url) {
      this.stencilUrl.push(url)
      this.showViewer = true
    },
    closeDialog() {
      this.billingFrom = {}
      this.visiable = false
    },
    handleClick(scope) {
      this.billingFrom.auditStatus = scope.auditStatus
      this.getDetail(scope.id)
    },
    // 获取开票抬头审核列表
    getData() {
      this.$https({
        method: 'post',
        url: '/invoiceHeader/invoiceHeaderApproveList',
        data: {
          page: this.page,
          size: this.size
        }
      })
        .then(res => {
          if (res.code == 0) {
            this.tableData = res.data.records || []
            this.total = res.data.total || 0
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    getDetail(id) {
      this.$https({
        method: 'post',
        url: '/invoiceHeader/getInvoiceHeaderById?id=' + id
      })
        .then(res => {
          if (res.code == 0) {
            this.billingFrom = Object.assign(res.data, this.billingFrom)
            this.visiable = true
            console.log(this.billingFrom)
          } else {
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log(err)
        })
    },
    getDataChange() {},
    getPagChange(data) {
      this.page = data.currentPage
      this.size = data.pagesize
      this.getData()
    },
    sortChange() {},
    addIndex(index) {
      return index + 1 + (this.page - 1) * this.size
    },
    tabRowClassName({ row, rowIndex }) {
      let index = rowIndex + 1
      if (index % 2 == 0) {
        return 'warning-row'
      }
    }
  }
}
</script>
<style lang="less" scoped>
#billingreview {
  height: 100%;
  .list-container {
    height: calc(100% - 62px);
    .tables {
      height: 100%;
    }
  }

  .dialog-wrap {
    width: 100%;
  }
  .form-con {
    border: 1px solid #d6d6d6;
    display: flex;
    padding: 20px 0;
    .left {
      width: 50%;
      border-right: 1px dashed #d6d6d6;
      padding: 0 50px;
    }
    .right {
      width: 50%;
      padding: 0 50px;
    }
  }
  /deep/ .left {
    .el-form-item__label {
      color: #666;
    }
    .el-form-item__content {
      color: #333;
    }
  }
  .billing_dialog {
    /deep/ .right {
      .el-form-item__label,
      .el-form-item__content {
        color: #333;
        font-size: 16px;
      }
      .el-form-item__content {
        font-weight: 600;
      }
    }
    /deep/ .el-form-item {
      margin-bottom: 0;
    }
    /deep/ .el-tabs__item {
      height: 32px;
      line-height: 30px;
    }
    /deep/ .el-button {
      width: 280px;
      color: #fff;
      background-color: #fa7355;
      border: none;
      border-radius: 5px;
    }
  }
}
</style>
